<!DOCTYPE html>
<html lang="en">
<head>
<{include file="public_html/header_tag.html"}>
	<title>课程表</title>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=hr20tx53PVWOwhMWxkipwE7tN1pstQ1S"></script>
</head>
<body>

<header class="brB">
	<div class="h_top">
		<div class="hLeft"><a href="/my/home" class="icoH icoReturn mt20"></a></div>
		<div class="hCenter"><span class="tit c-3ac9af">课程表</span></div>
	</div>
</header>
<div class="warp">
	<div class="pt20">
	<input type="text" name="lgn_lat" id="lgn_lat" value="" autocomplete="off" class="layui-input" readonly="readonly" style="display: none;">
	<div class="layui-input-block" id="allmap" style="display: none;"></div>  
		<ul class="b-FFFFFF">
			<{foreach from=$plan_list item=item}>
			<li class="p20 brB">
				<dl class="layout-box">
					<dd class="box-col">
						<div>
							<span class="fs26"><{$item['class_name']}></span>
							<!-- <span class="fs22 kb_btn_fa3838 r">新作业</span> -->
						</div>
						<div><span class="fs22 c-666666">班主任：<{$item['teacher_name']}></span></div>
						<div class="h40 oh"><span class="fs22 c-999999">上课时间：<{$item[ 'class_time']|date_format: '%Y-%m-%d %H:%M:%S'}></span></div>
						<a href="javascript:;" class="checkin" plan_id="<{$item['id']}>">签到</a>
					</dd>
				</dl>
			</li>
			<{/foreach}>
		</ul>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function() { 
	$(".checkin").click(function(){
		$(this).unbind("click");
		if("<{$schoo_location.longitude}>" <= 0 || "<{$schoo_location.latitude}>" <= 0){
			alert("该学校尚未设置经纬度，无法签到");
			return;
		}
		var plan_id = $(this).attr("plan_id");
		// 百度地图API功能
		var map = new BMap.Map("allmap");
		var point = new BMap.Point(116.331398,39.897445);
		map.centerAndZoom(point,12);
		map.enableScrollWheelZoom(true);
		var geolocation = new BMap.Geolocation();
		geolocation.getCurrentPosition(function(r){
			if(this.getStatus() == BMAP_STATUS_SUCCESS){
				var mk = new BMap.Marker(r.point);
				map.addOverlay(mk);
				map.panTo(r.point);
				$("#lgn_lat").val(r.point.lng + ", " + r.point.lat);
				var pointA = new BMap.Point(r.point.lng,r.point.lat);
				var pointB = new BMap.Point(<{$schoo_location.longitude}>,<{$schoo_location.latitude}>);
				var distance = (map.getDistance(pointA,pointB)).toFixed(2);
				if(distance > 10000){
					alert("您离教室的距离大于100米，无法签到！");
					return;
				}else{
					$.ajax({
						type: "POST",
						url: "/my/user/checkin",
						dataType:"json",
						data:{"plan_id":plan_id,"user_longitude":r.point.lng,"user_latitude":r.point.lat,"distance":distance},
						success: function(result){
							alert(result.msg);
						}
					})
				}
			}else {
				alert('failed'+this.getStatus());
			}
		},{enableHighAccuracy: true})
		/*$.ajax({
			type: "POST",
			url: "/tiku/ignore_get_subject_chapter",
			dataType:"json",
			data:{subject_id:subject_id},
			success: function(result){
				layer.close(ii);
				if(result.code == 1){
					var html ='';
					$.each(result.chapter_list, function(i, obj) {
						html += '<optgroup label="'+ obj.title+'">';
						if(obj.sub){
							$.each(obj.sub, function(j, obj1) {
								html += '<option value="'+obj1.id+'">'+obj1.title+'</option>';
							});
						}
						html += '</optgroup>'
					});
					$("#chapter_id").append(html);
					form.render('select');
				}
			}
		});*/
	})
});

</script>
</body>
</html>